package com.dong.CourseExer;

public class StudentTest2 {
    public static void main(String[] args) {
        Student[] students = new Student[]{
                new Student(1,"小红",22),
                new Student(2,"晓东",100),
                new Student(3,"林东松",122),
                new Student(4,"林福生",10),
                new Student(5,"李飞",38),
                new Student(6,"李四",42),
                new Student(7,"赵宇",12),
                new Student(8,"关羽",82),
                new Student(9,"刘备",88),

        };

        //遍历所有学生信息
        System.out.println("#########原始的学生信息#########");
        printStudentInfo(students);

        //使用冒泡排序按学生成绩排序
        System.out.println("#########按照成绩排序好的学生信息#########");
        sortStudentInfoByAge(students);
        printStudentInfo(students);
    }
    private static void printStudentInfo(Student[] students) {
        for (Student stu : students) {
            System.out.println(stu.toString());
        }
    }
    private static void sortStudentInfoByAge(Student[] students) {
        for (int i = 0; i < students.length - 1; i++) {
            for (int j = 0; j < students.length - i - 1; j++) {
                if (students[j].age < students[j + 1].age) {
                    Student temp = students[j];
                    students[j] = students[j + 1];
                    students[j + 1] = temp;
                }
            }
        }
    }
}






